<template>
  <div>
    <MHeader :back="true">首页</MHeader>
    <div class="content">
      <div v-if="loading">
        <Loading></Loading>
      </div>
      <template v-else>
        <Swiper :swiperSlides="sliders"></Swiper>

        <div class="container">
          <h3>热门图书</h3>
          <ul>
            <li v-for="book in hotBooks">
              <img :src="book.bookCover" alt="">
              <b>{{book.bookName}}</b>
            </li>
          </ul>
        </div>
      </template>
    </div>
  </div>
</template>
<script>
import MHeader from "../base/MHeader.vue";
import Swiper from "../base/Swiper.vue";
import Loading from '../base/Loading.vue';
import { getAll } from "../api";
export default {
  data() {
    return {
      sliders: [],
      hotBooks: [],
      loading: true
    };
  },
  components: {
    MHeader,
    Swiper,
    Loading
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      let [sliders, hotBooks] = await getAll();
      this.sliders = sliders;
      this.hotBooks = hotBooks;
      this.loading=false;
    },

  }
};
</script>
<style scoped lang="less">
h3 {
  color: #999;
  padding: 5px 0px;
}
.container {
  width: 90%;
  margin: 0 auto;
  ul {
    display: flex;
    flex-wrap: wrap;
    li {
      border-bottom: 1px solid #666;
      width: 45%;
      padding: 1%;
      text-align: center;
      img {
        width: 100%;
      }
    }
  }
}
</style>

